//
//  DiaochangController.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/5/12.
//  Copyright © 2016年 game. All rights reserved.
//

#import "DiaochangController.h"
#import "IslanSelectView.h"
#import "FujinSekectView.h"
#import "ZuijinSelectView.h"
#import "ShaiXuanSelectView.h"
#import "IslanTableview.h"
#import "InformView.h"
#import "IslanDescribCtll.h"
#import "IslanMapController.h"
#import "RootTableview.h"
#define selectViewhight (SCREEN_HEIGHT*0.06) //附近  等等个 选择btn 承载视图的高度

@interface DiaochangController ()<IslanSelectClick,FujinSekectDeleget,ZuijinSelectDeleget,ShaiXuanSelectDeleget,IsLanTabClickDeleget>

@property (nonatomic,strong) IslanSelectView *selectView;
@property (nonatomic,strong) FujinSekectView  *fujinView;
@property (nonatomic,strong) ZuijinSelectView *zuijinView;
@property (nonatomic,strong) ShaiXuanSelectView *shaixuanView;
@property (nonatomic,strong) IslanTableview *tableview;
@property (nonatomic,strong) NSArray *dataAry;

@end

@implementation DiaochangController

-(FujinSekectView *)fujinView{
    if (!_fujinView) {
        _fujinView = [[FujinSekectView alloc]initWithFrame:CGRectMake(0, 64+selectViewhight, SCREEN_WIDTH, screen_height-64-selectViewhight)];
        _fujinView.alpha = 0;
        _fujinView.deleget = self;
        
        [self.view addSubview:_fujinView];
    }
    return _fujinView;
}

-(ZuijinSelectView *)zuijinView{
    if (!_zuijinView) {
        _zuijinView =[[ZuijinSelectView alloc]initWithFrame:CGRectMake(0,64+selectViewhight, SCREEN_WIDTH, screen_height-64-selectViewhight)];
        _zuijinView.alpha = 0;
        _zuijinView.deleget = self;
        
        [self.view addSubview:_zuijinView];
    }
    return _zuijinView;
}

-(ShaiXuanSelectView *)shaixuanView{
    if (!_shaixuanView) {
        _shaixuanView = [[ShaiXuanSelectView alloc]initWithFrame:CGRectMake(0, 64+selectViewhight, SCREEN_WIDTH, screen_height-64-selectViewhight)];
        _shaixuanView.alpha = 0;
        _shaixuanView.deleget = self;
        [self.view addSubview:_shaixuanView];
    }
    return _shaixuanView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.selectView = [[IslanSelectView alloc]init];
    self.selectView.frame = CGRectMake(0,64, SCREEN_WIDTH, selectViewhight);
    self.selectView.backgroundColor = [UIColor whiteColor];
    self.selectView.deleget = self;
    [self.view addSubview:self.selectView];
    
    [self CreatTableview];
    
    self.tableview.dic = self.dic;
    self.tableview.url = _url;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdate:) name:@"MapShowAry" object:nil];
    

}
-(void)CreatTableview{
    
    self.tableview = [[IslanTableview alloc]initWithFrame:CGRectMake(0,64+selectViewhight, SCREEN_WIDTH, SCREEN_HEIGHT-44-32-64-selectViewhight) style:UITableViewStylePlain];
    self.tableview.Maindelget = self;
    [self.view addSubview:self.tableview];
    
}

-(void)setCharactModel:(DiaochangModel *)CharactModel{
    _CharactModel = CharactModel;
        
    self.fujinView.distanceModel = self.CharactModel.distance_type;
    self.fujinView.localCity = [self.Myud valueForKey:@"localName"];
    self.zuijinView.orderTypeAry = self.CharactModel.order_type;
    
    self.shaixuanView.isyujudian = self.isYujudian;
    self.shaixuanView.filtType = self.CharactModel.filt_type;
}

-(void)IsLanTabClickWhithDetail:(NSString *)detail AndLatitude:(NSString *)latitude AndLongitude:(NSString *)longitude AndLocaltion:(NSString *)localtion AndID:(NSString *)Id{

    IslanDescribCtll *desCreib = [IslanDescribCtll new];
    desCreib.isYuJuDian =  self.isYujudian;
    desCreib.detail = detail;
    desCreib.latitude = latitude;
    desCreib.longitude = longitude;
    desCreib.localtion = localtion;
    desCreib.ID = Id;
    
    [self.navigationController pushViewController:desCreib animated:YES];
}

-(void)CityChange{

    [self setCharactModel:self.CharactModel];
}

//离我最近tableview的cell点击
-(void)ZuijinAlphaIsCellClick:(BOOL)iscellClick WhithSting:(NSString *)string{
    
    [[[UIApplication sharedApplication]keyWindow ]endEditing:YES];
    self.selectView.zuijin.selected = NO;
    
    if (iscellClick) {//如果是点击cell  否则是点击半透明处
        [self.selectView.zuijin setTitle:string forState:UIControlStateNormal];
        
        NSString *ssss;
        
        if ([string isEqualToString:@"离我最近"]) {
            ssss = @"";
        }else if ([string isEqualToString:@"评价最高"]){
            ssss = @"score";
            
        }else if ([string isEqualToString:@"添加时间"]){
            ssss = @"addtime";
        }else if ([string isEqualToString:@"人气最高"]){
            ssss = @"comment";
        }
        
        self.tableview.order = ssss;
    }
}


-(void)FujinAlphaIsCellClick:(BOOL)iscellClick AndIsQuyu:(BOOL)isquyu WhithSting:(NSString *)string{
    
    if (iscellClick) {
        
        if (isquyu) {
            
            self.tableview.area_code = @{@"area_code":string};
            
        }else{
            
            self.tableview.range = @{@"range":string};
            
        }
        
    }
    
    [[[UIApplication sharedApplication]keyWindow ]endEditing:YES];
    self.selectView.fujin.selected = NO;
    
}

-(void)ShanXuanAlpha{
    [[[UIApplication sharedApplication]keyWindow ]endEditing:YES];
    self.selectView.shaixuan.selected = NO;
}
#pragma mark--点击筛选下拉列表上的确定
-(void)SureClickWhithDic:(NSDictionary *)dic{
    [[[UIApplication sharedApplication]keyWindow ]endEditing:YES];
    self.selectView.shaixuan.selected = NO;
    self.tableview.shaiXuanDic = dic;
}
#pragma mark--点击筛选下拉列表上的地图 跳转到地图控制器
-(void)MapAndListChangeWhith:(BOOL)ismap{
    
    if (ismap) {
        
        IslanMapController *map = [IslanMapController new];
        map.dataAry = self.dataAry;
        [self.navigationController pushViewController:map animated:YES];
    }
}


#pragma mark--- self.selectView 顶部三个btn点击展开tableview下拉列表 deleget
-(void)FujinClick:(UIButton *)fujin{
    
    self.fujinView.alpha = fujin.selected;
}

-(void)ZuijinClick:(UIButton *)zuijin{
    
    self.zuijinView.alpha = zuijin.selected;
}

-(void)ShaiXuanClick:(UIButton *)shaixuan{
    
    self.shaixuanView.alpha = shaixuan.selected;
}
-(void)didUpdate:(NSNotification *)notification{
    
    NSArray *ary =  notification.userInfo[@"sss"];
    
    self.dataAry  = [ary mutableCopy];
}

@end